-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[PROC_YTGZ_HXZJ_污染地块]
	(
	@newShape varchar(MAX),
	@coordinateSystem int,
	@QYGM  varchar(128)
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;


	DECLARE @g geometry = geometry::STGeomFromText(@newShape,@coordinateSystem);
	DECLARE @shapeArea float = @g.STArea();

SELECT
    ISNULL(geometry::UnionAggregate(@g.STIntersection(Shape)).STArea(),0) as [overArea],
	'ZYMJ' as [title],
	'检测情况' as labelName,
	ISNULL(geometry::UnionAggregate(@g.STIntersection(Shape)).STAsText(),'') as [overShape],
	CASE WHEN geometry::UnionAggregate(@g.STIntersection(Shape)).STArea() > 0 THEN 0 ELSE  1 END as [resultCode]
	FROM [SZ_Onemap_2000].[dbo].[T土地利用_T土地污染_BUFFER]
	WHERE @g.STIntersects(Shape) = 1 and @g.STIntersection(Shape).STArea() and QYGM=@QYGM>

END
GO
